#!/bin/bash


### 使用Anaconda3来安装python依赖
if [[ $# -ne 2 ]]; then
    echo "The format is as follows:"
    echo "bash Anaconda3.sh.sh buildpath installpath"
    echo ":param buildpath: 应用构建绝对路径"
    echo ":param installpath: 应用安装绝对路径"
    exit 1
fi


if [[ ! "$1" =~ ^/.* || ! -d "$1" || "$1" = "/" ]]; then echo "请输入正确的构建路径"; exit 1; fi
if [[ ! "$2" =~ ^/.* || ! -d "$2" || "$2" = "/" ]]; then echo "请输入正确的安装路径"; exit 1; fi

buildpath=$1
installpath=$2
if [[ "$1" =~ .*/$ ]]; then buildpath=${buildpath%/*}; fi
if [[ "$2" =~ .*/$ ]]; then installpath=${installpath%/*}; fi
[[ "$buildpath" == "$installpath" ]] && echo "构建路径与安装路径需为不同路径" && exit 1
yum install -y wget tar cmake environment-modules --nogpgcheck
wget -t 0 -c -P $buildpath https://repo.anaconda.com/archive/Anaconda3-2021.11-Linux-aarch64.sh

bash  $buildpath/Anaconda3-2021.11-Linux-aarch64.sh -b -p $installpath/Anaconda3

$installpath/Anaconda3/bin/conda  config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
$installpath/Anaconda3/bin/conda  config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
$installpath/Anaconda3/bin/conda  config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge 
$installpath/Anaconda3/bin/conda  config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/

echo "y" > input.data
$installpath/Anaconda3/bin/conda create --name python27 python=2.7 < input.data
rm -rf input.data

cat>"$installpath/Anaconda3/anaconda3_modulefiles"<<EOF
#%Module1.0
conflict Anaconda3
variable modfile [file normalize [info script]]
proc getModulefileDir {} {
    variable modfile
    set modfile_path [file dirname \$modfile]
    return \$modfile_path
}
set pwd [getModulefileDir]
set Anaconda3 \$pwd
setenv Anaconda3 \$Anaconda3
prepend-path PATH \$Anaconda3/bin
EOF

rm -rf  $buildpath/*
